package sk.hackcraft.util.generator.empirical;

import sk.hackcraft.util.generator.DiscreteRandom;

public class EmpiricalItem implements Comparable<EmpiricalItem>
{
	public static EmpiricalItem getSearchItem(double number)
	{
		return new EmpiricalItem(number);
	}
	
	private final double cumulativeValue;
	private final DiscreteRandom random;
	
	private EmpiricalItem(double cumulativeValue)
	{
		this(cumulativeValue, null);
	}
	
	public EmpiricalItem(double cumulativeValue, DiscreteRandom random)
	{
		this.cumulativeValue = cumulativeValue;
		this.random = random;
	}

	public double getCumulativeValue()
	{
		return cumulativeValue;
	}

	public int nextNumber()
	{
		return random.next();
	}
	
	@Override
	public int compareTo(EmpiricalItem o)
	{
		if(this.getCumulativeValue() > o.getCumulativeValue())
		{
			return 1;
		}
		else if(this.getCumulativeValue() < o.getCumulativeValue())
		{
			return -1;
		}
		else
		{
			return 0;
		}
	}
}
